Skip to content

Conversation

@enyinnaya1234
Copy link
Contributor

@enyinnaya1234 enyinnaya1234 commented May 3, 2025

Closes #47
Overview

This PR introduces several key improvements to the project allocation logic, focusing on enhanced input validation and increased event transparency. These changes ensure stricter integrity checks and improved observability of milestone creation, aligning with the project's goals for secure and accountable financial management as outlined in the BudgetChain Contracts README.
✨ Key Changes
✅ Validation Enhancements

Project Owner Address Validation

    Rejects a zero (0) project_owner address by throwing ERROR_ZERO_ADDRESS.

Milestone Description Validation

    Ensures all milestone descriptions are non-empty felt252 values.

    Invalid descriptions throw ERROR_INVALID_MILESTONE_DESCRIPTION.

Milestone Array Checks

    Rejects empty milestone arrays (both descriptions and amounts) with ERROR_NO_MILESTONES.

Budget Sanity Check

    Prevents allocation of projects with a total_budget of zero.

🧠 Validation Consistency

The following existing validations remain intact:

Unauthorized caller → ERROR_CALLER_NOT_ORG

Invalid organization → ERROR_UNAUTHORIZED

Mismatched milestone arrays → ERROR_ARRAY_LENGTH_MISMATCH

Budget sum mismatch → ERROR_BUDGET_MISMATCH

🛠️ Implementation Details

Storage Updates

    Updates project_owners (LegacyMap<u64, ContractAddress>) with the project_owner.

Milestone Processing

    Each milestone is stored in milestones: Map<(u64, u64), Milestone>.

    Emits a MilestoneCreated event per milestone with:

        Organization

        Project ID

        Description

        Amount

        Creation timestamp

Project Logic

    Retains logic for creating and storing the Project struct.

    Continues to emit the ProjectAllocated event.

✅ Acceptance Criteria

Rejects zero project_owner address → ERROR_ZERO_ADDRESS

Rejects empty milestone arrays → ERROR_NO_MILESTONES

Rejects invalid descriptions → ERROR_INVALID_MILESTONE_DESCRIPTION

Updates project_owners storage correctly

Emits MilestoneCreated for each milestone

Continues to emit ProjectAllocated event

All tests pass, including edge cases for zero values and empty arrays

Let me know if you'd like a changelog entry or release notes template added too.

Screenshot from 2025-05-03 09-14-51

Copy link
Contributor

@anonfedora anonfedora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@anonfedora anonfedora merged commit a5c59a2 into BudgetChain:main May 6, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SC]: allocate_project_budget with Additional Validation and Milestone Events

2 participants